//
//  AYSFavouriteHandle.m
//  AiYingShiProject
//
//  Created by lanou on 15/11/4.
//  Copyright (c) 2015年 李晓理. All rights reserved.
//

#import "AYSFavouriteHandle.h"
#import <sqlite3.h>
#import "AYSPlayDataModel.h"
#import "AYSDatabaseHandle.h"
#import "AYSSpecialDetialModel.h"
@interface AYSFavouriteHandle()

@property (nonatomic,strong) NSMutableArray *movieArray;
@property (nonatomic,strong) NSMutableArray *videoArray;
@end
@implementation AYSFavouriteHandle

+ (instancetype)shareInstance
{
    static AYSFavouriteHandle *handle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        handle = [[AYSFavouriteHandle alloc] init];
    });
    return handle;
}

// 从数据库读取数据源
- (void)setupMovieDataSource
{
    self.movieArray = [[[AYSDatabaseHandle shareInstance]selectAllMovie] mutableCopy];
}

// 获取电影的个数
- (NSInteger)countOfMovie
{
    return [_movieArray count];
}
// 获取某个电影对象
- (AYSPlayDataModel *)movieForRow:(NSInteger)row
{
    return _movieArray[row];
}

// 删除某个电影对象
- (void)deleteMovieForRow:(NSInteger)row
{
    // 从数据库删除
    [[AYSDatabaseHandle shareInstance] deleteMovie:[self movieForRow:row]];
    
    // 从数据源删除
    [_movieArray removeObjectAtIndex:row];
}

#pragma mark ----------Video----------数据源
// 从数据库读取数据源
- (void)setupVideoDataSource
{
     self.videoArray = [[[AYSDatabaseHandle shareInstance]selectAllVideo] mutableCopy];
}

// 获取视频的个数
- (NSInteger)countOfVideo
{
    return _videoArray.count;
}

// 获取某个视频对象
- (AYSSmallListModel *)videoForRow:(NSInteger)row
{
    return _videoArray[row];
}

// 删除某个视频对象
- (void)deleteVideoForRow:(NSInteger)row
{
    // 从数据库删除
    [[AYSDatabaseHandle shareInstance] deleteVideo:[self videoForRow:row]];
    
    // 从数据源删除
    [_videoArray removeObjectAtIndex:row];

}




@end
